function checkLogin() {
	if (form1.userLoginCode.value == "") {
		$("#tip").html("<font color=\"red\">请输入登录账号</font>");
		return false;
	}
	if (form1.password.value == "") {
		$("#tip").html("<font color=\"red\">请输入登录密码</font>");
		return false;
	}
	if (form1.codeimage.value == "") {
		$("#tip").html("<font color=\"red\">请输入图形验证码</font>");
		return false;
	}
	productkeyandsub(desRandom);
}

function productkeyandsub(json) {
	var userLoginCode = strEnc($("#userLoginCode").val(), json);
	var password = strEnc($("#password").val(), json);
	$.ajax({
		url : ctp + "/loginController/login.shtml",
		data : {
			userLoginCode : userLoginCode,
			password : password,
			pageLabel : pageLabel,
			codeimage : $("#codeimage").val()
		},
		type : 'POST',
		dataType : 'json',
		timeout : 20000,
		success : function(json) {
			if (json.success == true) {
				var loginUserType = json.loginUserType;
				if (loginUserType == '0' || loginUserType == '2') {
					location.href = ctp + "/loginController/home.shtml";
				} else {
					location.href = ctp + "/loginController/home.shtml";
				}
			} else if (json.success == false) {
				$("#tip").html("<font color=\"red\">" + json.msg + "</font>");
			}
		},
		error : function() {
			jalert9("处理超时,请重新登录！");
			location.reload();
		}
	});
}
// 登入enter快捷键
function okd() {
	if (event.keyCode == 13)
		checkLogin();
};
function okd1() {
	if (event.keyCode == 13)
		event.keyCode = 9;
};

function getSmessageCode() {
	var codeimage = form1.codeimage.value;
	if (typeof (codeimage) == 'undefined' || codeimage == null
			|| codeimage == '' || $.trim(codeimage) == '') {
		$("#tip").html("请先输入图形验证码,再点击获取短信验证码");
		return false;
	} else {
		$.ajax({
			url : ctp + "/loginController/loginImagecode.shtml",
			data : {
				codeimage : $("#codeimage").val(),
				pageLabel : pageLabel
			},
			type : 'POST',
			dataType : 'json',
			timeout : 20000,
			success : function(json) {
				if (json.success == "1") {
					getsmgCode();
				} else {
					$("#tip").html("图形验证码输入错误");
					return false;
				}
			},
			error : function() {
				jalert9("验证超时,请刷新页面！");
				location.reload();
			}
		});
	}
}

// 忘记密码
function forgetPwd() {
	var userId = $("#userLoginCode").val();
	dialogWin(550, 350, ctp + "/pubController/forgetPwdPage.shtml?userId="
			+ userId, "忘记密码");
}

$(document).keydown(function(e) {
	if (e.keyCode == 13) {
		checkLogin();
	}
});
